using System.Collections;
using I2.Loc;
using UnityEngine;
using UnityEngine.SceneManagement;

public class TutorialShowMessageInGame : MonoBehaviour
{
	private enum MessageType
	{
		none = 0,
		Sandbox = 1,
		PvpMap = 2,
		Adventure = 3
	}

	public GameObject messageWindow;

	public UILabel labelMessage;

	public float timeWaitShowMessage = 3f;

	public float timeShowMessage = 5f;

	private string needShow = "TutorialMessagNeedShow";

	private string tableName = "respect_tutor/";

	private bool isRun;

	private void Awake()
	{
	}

	private void Update()
	{
		if (!ManagerPreloadingSectors.thisScript.isFirstLoading && !isRun)
		{
			MessegeCanShow();
			isRun = true;
		}
	}

	private void MessegeCanShow()
	{
		MessageType messageType = WhatGameMode();
		if (BCWStorage.Get<bool>(needShow + messageType))
		{
			StartCoroutine(ShowMessage(messageType));
		}
		else
		{
			base.gameObject.SetActive(false);
		}
	}

	private IEnumerator ShowMessage(MessageType type)
	{
		yield return new WaitForSeconds(timeWaitShowMessage);
		labelMessage.text = ScriptLocalization.Get(tableName + "In_" + type);
		messageWindow.SetActive(true);
		StartCoroutine(MessegeEndShow(type));
	}

	private IEnumerator MessegeEndShow(MessageType type)
	{
		BCWStorage.Set(needShow + type, false);
		yield return new WaitForSeconds(timeShowMessage);
		messageWindow.SetActive(false);
		base.gameObject.SetActive(false);
	}

	private MessageType WhatGameMode()
	{
		if (GameController.instance != null)
		{
			if (settings.offlineMode && SceneManager.GetActiveScene().name == "Level1")
			{
				return MessageType.Adventure;
			}
			if (!settings.offlineMode)
			{
				if (SceneManager.GetActiveScene().name == "Level1")
				{
					return MessageType.Sandbox;
				}
				return MessageType.PvpMap;
			}
		}
		return MessageType.none;
	}
}
